package com.boot.main.controller;

import com.boot.main.entity.CcomMenu;
import com.boot.main.service.IMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/v1/api")
@Api(tags = "菜单模块")
public class MenuController {
    @Resource
    private IMenuService menuService;

    @RequestMapping(value="/menus", method = RequestMethod.GET)
    @ApiOperation(value = "获取菜单列表")
    public Object getMenus(){
        return menuService.getMenus();
    }

    @RequestMapping(value="/menu", method = RequestMethod.POST)
    @ApiOperation(value = "保存菜单")
    public Object saveMenu(@RequestBody CcomMenu menu){
        menu.setCreate_time(new Date().getTime());
        return menuService.saveMenu(menu);
    }

    @RequestMapping(value="/menu/{id}", method = RequestMethod.PUT)
    @ApiOperation(value="更新菜单")
    public Object updateMenu(@RequestBody CcomMenu menu){
        menu.setCreate_time(new Date().getTime());
        return menuService.updateMenu(menu);
    }

    @RequestMapping(value="/menu/{id}", method = RequestMethod.DELETE)
    @ApiOperation(value="删除菜单")
    public Object deleteMenu(@PathVariable long id){
        return menuService.deleteMenu(id);
    }

    @RequestMapping(value="/menu/tree", method = RequestMethod.GET)
    @ApiOperation(value = "获取菜单树")
    public Object getMenuTree(){
        return menuService.getMenuTree();
    }

    @RequestMapping(value = "/menu/tree/list/{role_id}", method = RequestMethod.GET)
    @ApiOperation(value="获取菜单树列表")
    public Object getMenuTreeList(@PathVariable Long role_id){
        return menuService.getMenuTreeList(role_id);
    }

    @RequestMapping(value = "/menu/tree/permissions/{role_id}", method = RequestMethod.GET)
    @ApiOperation(value="获取菜单权限树列表")
    public Object getMenuTreePermissions(@PathVariable Long role_id){
        return menuService.getMenuTreePermissions(role_id);
    }

    @RequestMapping(value = "/menu/user/permissions", method = RequestMethod.GET)
    @ApiOperation(value="获取登录用户的菜单权限")
    public Object getMenuPermissionsByUserRole(@RequestParam("role_ids") String role_ids){
        return menuService.getMenuPermissionsByUserRole(role_ids);
    }
}